package com.ifood.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ifood.common.core.domain.R;
import com.ifood.common.core.domain.entity.IFoodStoreInfo;
import com.ifood.common.core.domain.vo.StoreSelectVo;
import com.ifood.system.service.IIFoodStoreInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ifood.common.annotation.Log;
import com.ifood.common.core.controller.BaseController;
import com.ifood.common.core.domain.AjaxResult;
import com.ifood.common.enums.BusinessType;
import com.ifood.common.utils.poi.ExcelUtil;
import com.ifood.common.core.page.TableDataInfo;

/**
 * 门店信息Controller
 *
 * @author ifood
 * @date 2024-01-09
 */
@RestController
@Api(tags = "门店信息")
@RequestMapping("/system/store")
public class IFoodStoreInfoController extends BaseController {
    @Autowired
    private IIFoodStoreInfoService iFoodStoreInfoService;

    /**
     * 查询门店信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:store:list')")
    @GetMapping("/list")
    @ApiOperation("查询门店信息列表")
    public TableDataInfo list(IFoodStoreInfo iFoodStoreInfo) {
        startPage();
        List<IFoodStoreInfo> list = iFoodStoreInfoService.selectIFoodStoreInfoList(iFoodStoreInfo);
        return getDataTable(list);
    }

    /**
     * 导出门店信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:store:export')")
    @Log(title = "门店信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IFoodStoreInfo iFoodStoreInfo) {
        List<IFoodStoreInfo> list = iFoodStoreInfoService.selectIFoodStoreInfoList(iFoodStoreInfo);
        ExcelUtil<IFoodStoreInfo> util = new ExcelUtil<IFoodStoreInfo>(IFoodStoreInfo.class);
        util.exportExcel(response, list, "门店信息数据");
    }

    /**
     * 获取门店信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:store:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取门店信息详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(iFoodStoreInfoService.selectIFoodStoreInfoById(id));
    }

    /**
     * 新增门店信息
     */
    @PreAuthorize("@ss.hasPermi('system:store:add')")
    @Log(title = "门店信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增门店信息")
    public AjaxResult add(@RequestBody IFoodStoreInfo iFoodStoreInfo) {
        return toAjax(iFoodStoreInfoService.insertIFoodStoreInfo(iFoodStoreInfo));
    }

    /**
     * 修改门店信息
     */
    @PreAuthorize("@ss.hasPermi('system:store:edit')")
    @Log(title = "门店信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改门店信息")
    public AjaxResult edit(@RequestBody IFoodStoreInfo iFoodStoreInfo) {
        return toAjax(iFoodStoreInfoService.updateIFoodStoreInfo(iFoodStoreInfo));
    }

    /**
     * 删除门店信息
     */
    @PreAuthorize("@ss.hasPermi('system:store:remove')")
    @Log(title = "门店信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除门店信息")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iFoodStoreInfoService.deleteIFoodStoreInfoByIds(ids));
    }

    @GetMapping("/stores")
    @ApiOperation("门店下拉列表")
    public R<List<StoreSelectVo>> selectStores() {
        return iFoodStoreInfoService.selectStoreList();
    }

}
